<template>
	<view>
		<uni-search-bar placeholder="搜索用户姓名" @confirm="search" />
		<uni-list><uni-list-item v-for="user in memberList" :title="user.name" v-model="keywordSearchValue" /></uni-list>
		<uni-load-more iconType="circle" :status="status" @clickLoadMore="getMoreMember" />
	</view>
</template>

<script>
export default {
	data() {
		return {
			status: 'more',
			apiUrl: 'http://localhost:8080/',
			pageNum: 1,
			pageSize: 5,
			memberList: [],
			keywordSearchValue: ''
		};
	},
	onLoad: function(option) {
		this.activityId = option.activityId;
		this.activityName = option.activityName;
		uni.setNavigationBarTitle({
			title: this.activityName
		});
		this.getMember();
	},
	onPullDownRefresh() {
		this.pageNum = 1;
		this.getMember();
	},
	methods: {
		getMoreMember() {
			this.pageNum++;
			this.getMember();
		},
		search(res) {
			this.keywordSearchValue=res.value;
			this.pageNum = 1;
			this.getMember();
		},
		getMember() {
			uni.request({
				method: 'GET',
				url: this.apiUrl + 'entry/' + this.activityId,
				header: {
					Authorization:"Bearer " + uni.getStorageSync('token')
				},
				data: {
					keyword: this.keywordSearchValue,
					pageNum: this.pageNum,
					pageSize: this.pageSize
				},
				success: res => {
					console.log(res.data);
					if (this.pageNum <= 1) {
						this.memberList = [];
					}
					let originSize = this.memberList.length;
					this.memberList.push.apply(this.memberList, res.data.records);
					let deltaSize = res.data.records.length;
					if (res.data.total <= originSize + deltaSize) {
						this.status = 'noMore';
					} else {
						this.status = 'more';
					}
					uni.stopPullDownRefresh();
				},
				fail: err => {
					this.pageNum -= 1;
					reject(err);
					return uni.showToast({
						icon: 'loading',
						title: '请求失败'
					});
				}
			});
		}
	}
};
</script>

<style></style>
